/*
 * @Descripttion: 
 * @version: V1.0.0
 * @Author: Maverick
 * @Date: 2025-03-29 19:33:18
 * @LastEditors: Maverick
 * @LastEditTime: 2025-03-29 20:16:37
 */
#include "gtest/gtest.h"
#include "../include/sqlist.h"
#include <string>
#include <iostream>

using namespace maverick::sqlist;

// 定义测试类
class SqListTest : public ::testing::Test {
protected:
    void SetUp() override {
        list = new maverick::sqlist::SqList<int>(10); // 初始化容量为10的线性表
        for (int i = 0; i < 5; ++i) {
            list->Insert(i, i + 1); // 插入 1, 2, 3, 4, 5
        }
    }

    void TearDown() override {
        delete list; // 释放内存
    }

    SqList<int>* list;
};

// 测试初始化和基本操作
TEST_F(SqListTest, InitializationAndBasicOperations) {
    // 测试初始长度
    EXPECT_EQ(list->Length(), 5);

    // 测试是否为空
    EXPECT_FALSE(list->Empty());

    // 测试获取元素
    int elem;
    EXPECT_TRUE(list->GetElem(2, elem));
    EXPECT_EQ(elem, 3);

    // 测试设置元素
    EXPECT_TRUE(list->SetElem(2, 100));
    EXPECT_TRUE(list->GetElem(2, elem));
    EXPECT_EQ(elem, 100);

    // 测试删除元素
    EXPECT_TRUE(list->Delete(2, elem));
    EXPECT_EQ(elem, 100);
    EXPECT_EQ(list->Length(), 4);

    // 测试插入元素
    EXPECT_TRUE(list->Insert(2, 50));
    EXPECT_EQ(list->Length(), 5);
    EXPECT_TRUE(list->GetElem(2, elem));
    EXPECT_EQ(elem, 50);
}

// 测试边界条件
TEST_F(SqListTest, BoundaryConditions) {
    int elem;

    // 测试下界
    EXPECT_TRUE(list->GetElem(0, elem));
    EXPECT_EQ(elem, 1);

    // 测试上界
    EXPECT_TRUE(list->GetElem(4, elem));
    EXPECT_EQ(elem, 5);

    // 测试越界访问
    EXPECT_FALSE(list->GetElem(-1, elem));
    EXPECT_FALSE(list->GetElem(5, elem));

    // 测试空列表操作
    SqList<int> emptyList(5);
    EXPECT_TRUE(emptyList.Empty());
    EXPECT_EQ(emptyList.Length(), 0);
    EXPECT_FALSE(emptyList.GetElem(0, elem));
}
